<template>
	<view>
		<u-navbar :is-back="false"></u-navbar>
		
		<u-notice-bar duration="1000" font-size="30" type="primary" mode="horizontal" :list="list"></u-notice-bar>
		
		<view style="padding-top: 50rpx;">
			<u-swiper effect3d :list="swiperList" name="img" height="375" @click="toVideo"></u-swiper>
		</view>
			
		<view class="list">
			<view v-for="(item,index) in homeList" :key="index" class="list-item">
				<view class="list-item-title">
					<text>{{item.name}}</text>
				</view>
				<view v-for="(item2,index2) in item.children" :key="index2" class="list-item-children"
					@click="toOther(item2)">
					<view class="list-item-children-img">
						<!-- <image :src="item2.img" mode=""></image> -->
						<u-image width="100%" height="160rpx" :src="item2.img" :fade="true" duration="500">
							<u-loading slot="loading"></u-loading>
						</u-image>
					</view>
					<view class="list-item-children-text">
						<text class="one u-line-1">
							{{item2.title}}
						</text>
						<text class="two u-line-3">
							{{item2.intro}}
						</text>
					</view>
				</view>
			</view>
		</view>

		<Tabbar></Tabbar>
	</view>
</template>

<script>
	import {
		getSwiper,
		getHomeGoodList,
		getHomeList
	} from '../../utils/home.js'

	export default {
		data() {
			return {
				swiperList: [],

				homeList: [],

				list: ['还躺在被窝吃零食刷视频睡懒觉吗', '快来加入我们一起内卷吧!!!']
				// book:[],
				// blog:[],
				// video:[],
			}
		},
		methods: {
			//获取轮播图
			async getSwiper() {
				let result = await getSwiper()
				if (result.code === 200) {
					this.swiperList = result.data
				}
			},
			//获取精选列表
			async getGood() {
				let result = await getHomeGoodList()
				if (result.code === 200) {
					// this.video = result.Video
					// this.book = result.e_book
					// this.blog = result.Blog
					this.homeList.push({
						name: '精选手册',
						children: result.data.e_book
					})
					this.homeList.push({
						name: '精选博客',
						children: result.data.Blog
					})
					this.homeList.push({
						name: '精选视频',
						children: result.data.Video
					})
				}
			},
			//跳转去相关页面
			toOther(item) {
				console.log(item.type)
				if (item.type === 'book') {
					uni.navigateTo({
						url: `/subpkg/studyList/studyList?book_id=${item.book_id}&title=${item.title}&intro=${item.intro}`
					})
				} else if (item.type === 'blog') {
					uni.navigateTo({
						url: `/subpkg/blogDetail/blogDetail?blog_id=${item.blog_id}`
					})
				} else {
					uni.navigateTo({
						url: `/subpkg/videoDetail/videoDetail?id=${item.video_id}`
					})
				}
			},
			toVideo(index) {
				let id = this.swiperList[index].video_id
				uni.navigateTo({
					url: `/subpkg/videoDetail/videoDetail?id=${id}`
				})
			}
		},
		onLoad() {
			this.getSwiper()
			this.getGood()
		}
	}
</script>

<style lang="scss" scoped>
	// .zhanwei {

	// 	height: 44px;
	// 	width: 100%;
	// 	background-color: white;
	// 	position: sticky;
	// 	top: 0;
	// 	z-index: 999;
	// 	opacity:0;
	// }

	// .logo{
	// 	width: 90%;
	// 	margin: 0 auto;

	// 	image{
	// 		width: 40%;
	// 		height: 100rpx;
	// 	}
	// }
	.list {
		padding-top: 70rpx;
		width: 95%;
		margin: 0 auto;

		.list-item {
			padding-bottom: 50rpx;

			.list-item-title {
				font-size: 40rpx;
				font-weight: bold;
				padding-bottom: 20rpx;
			}

			.list-item-children {
				display: flex;
				width: 100%;
				padding-bottom: 40rpx;

				.list-item-children-img {
					width: 30%;

					// image{
					// 	width: 100%;
					// 	height: 160rpx;
					// 	border-radius: 10px;
					// }
				}

				.list-item-children-text {
					width: 70%;
					padding-left: 20rpx;
					display: flex;
					flex-direction: column;

					.one {
						font-size: 35rpx;
						font-weight: bold;
						padding-bottom: 15rpx;
					}

					.two {
						font-size: 28rpx;
						color: #909399;
					}
				}
			}
		}
	}
</style>
